<template>
  <!-- 玩家账户管理 -->
  <div class="app-container">
    <div class="app-wrap">
      <search-table ref="table" :table-loading="listLoading" :table-data="dataList" @query="getDataList(true)" @reset="refresh(false)">
        <template v-slot:row>
          <el-form-item class="flex">
            <el-select v-model="listQuery.search_type" placeholder="请选择条件" filterable>
              <el-option :label="item.label" :value="item.value" v-for="(item,index) in searchData" :key="index"></el-option>
            </el-select>
            <el-input class="width200" type="text" v-model="listQuery.search_value" clearable placeholder="请输入搜索的值"></el-input>
          </el-form-item>
          <el-form-item label="注册时间:" label-width="80px">
            <el-date-picker is-range v-model="listQuery.registerTime" type="daterange" range-separator="至" 
            start-placeholder="开始日期" end-placeholder="结束日期" class="full-width-input time-box" 
            :default-time="['00:00:00', '23:59:59']" clearable></el-date-picker>
          </el-form-item>
           <el-form-item label="登录时间:" label-width="80px">
            <el-date-picker is-range v-model="listQuery.loginTime" type="daterange" range-separator="至" 
            start-placeholder="开始日期" end-placeholder="结束日期" class="full-width-input time-box" 
            :default-time="['00:00:00', '23:59:59']" clearable></el-date-picker>
          </el-form-item>
          <el-form-item label="渠道:" label-width="50px">
            <el-select v-model="listQuery.agent_id" placeholder="请选择渠道" filterable >
              <el-option label="全部" value="" ></el-option>
              <el-option :label="'【'+item.value+'】'+item.label" :value="item.value" v-for="(item, index) in channelData" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否封禁:" label-width="90px">
            <el-select v-model="listQuery.ban_type" placeholder="请选择条件" filterable>
              <el-option label="全部" :value="0" ></el-option>
              <el-option :label="item.label" :value="item.value" v-for="(item, index) in bannedData" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否在线:" label-width="90px">
            <el-select v-model="listQuery.is_line" placeholder="请选择条件" filterable>
              <el-option label="全部" :value="-1" ></el-option>
              <el-option label="在线" :value="1" ></el-option>
              <el-option label="离线" :value="0" ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="注册IP:" label-width="60px">
            <el-input type="text" v-model="listQuery.reg_ip" clearable placeholder="请输入注册IP"/>
          </el-form-item>
          <el-form-item label="总充值>=:" label-width="80px">
            <el-input type="number" v-model="listQuery.pay_money" clearable placeholder="请输入总充值金额"/>
          </el-form-item>
          <el-form-item label="总提现>=:" label-width="80px">
            <el-input type="number" v-model="listQuery.cash_money" clearable placeholder="请输入总提现金额"/>
          </el-form-item>
        </template>
        <template v-slot:actions>
          <el-button type="info" size="mini" icon="el-icon-refresh" @click="getDataList">刷新</el-button>
          <el-button size="mini" v-permission="'user.type'" :disabled="!checkedItem" type="primary" @click="isShowTypeDetails = true" icon="el-icon-s-help">设置账户类型</el-button>
          <el-button size="mini" v-permission="'user.type'" type="primary" @click="addAccountShow" icon="el-icon-plus">添加账号</el-button>
          <el-button size="mini" v-permission="'resource.deduct'" :disabled="!checkedItem" type="danger" @click="isShowPropDetails = true" icon="el-icon-error">道具扣除</el-button>
          <el-button size="mini" v-permission="'user.ban'" type="danger" :disabled="!checkedItem?true:false || checkedItem.ban_type==1?false:true" @click="isShowDetails = true, isBanned=[],bannedReason=''" icon="el-icon-circle-close">封禁</el-button>
          <el-button size="mini" v-permission="'user.ban'" type="success" :disabled="!checkedItem?true:false || checkedItem.ban_type==1?true:false" @click="isShowDetails = true,isBanned=[1]" icon="el-icon-circle-check">解封</el-button>
        </template>
        <template>
          <el-table-column align="center" type="index" width="50">
            <template slot-scope="scope">
              <el-radio v-model="scope.row.isChecked" :label="true" @change="handleCurrentChange(scope.row)">{{ '' }}</el-radio>
            </template>
          </el-table-column>
          <el-table-column prop="agent_id" label="渠道名" align="center" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-show="scope.row.agent_id">【{{scope.row.agent_id}}】{{ $public.channelLabel(scope.row.agent_id) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="id" label="玩家ID" align="center" width="100"/>
          <el-table-column prop="nick_name" label="昵称" align="center" width="180" show-overflow-tooltip>
            <template slot-scope="scope">
              <span class="item_details" @click="handleCurrentChange(scope.row),isShowUserDetails = true">{{ scope.row.nick_name }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="account" label="账户" align="center" width="150"/>
          <el-table-column prop="account" align="center" label="登录验证码" width="100">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click.stop="getCode(scope.row)">验证码</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="vip_level" label="VIP等级" align="center" width="90"/>
          <!-- <el-table-column prop="nick_name" label="修改密码" align="center" width="90">
            <template slot-scope="scope">
              <el-button size="mini" type="warning" @click.stop="isShowPasswordDetails = true,handleCurrentChange(scope.row)" icon="el-icon-edit"></el-button>
            </template>
          </el-table-column> -->
          <el-table-column prop="mobile" label="手机号" align="center" width="150"/>
          <el-table-column prop="ip_count" label="注册IP管理数" align="center" width="120">
            <template slot-scope="scope">
              <span class="item_details" @click="getAccountIpList(scope.row)">{{ scope.row.ip_count }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="account_type" label="账户类型" align="center" width="150">
            <template slot-scope="scope">
              <el-tag :type="accountTag(scope.row.account_type)">{{ accountType(scope.row.account_type)}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="is_kol" label="是否是KOL"  width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.is_kol==1?'success':'info'">{{ scope.row.is_kol==1?'KOL':'否'}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="is_line" label="是否在线" align="center" width="100">
            <template slot-scope="scope">
              <el-tag :type="scope.row.is_line==1?'success':'info'">{{ scope.row.is_line==1?'在线':'离线'}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="ban_type" label="是否封禁" align="center" width="180">
            <template slot-scope="scope">
              <!-- <el-tag :type="bannedTag(scope.row.ban_type)">{{ bannedType(scope.row.ban_type) }}</el-tag> -->
              <div>{{ bannedType(scope.row.ban_type) }}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="share_url" label="分享链接" width="120">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" :disabled="!scope.row.share_url" @click.stop="shareUrl(scope.row)">分享链接</el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="user_name" label="登录" width="100">
            <template slot-scope="scope">
              <el-button disabled size="mini" type="primary" @click.stop="loginManage(scope.row)">登 录</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="vip_level" label="vip等级" align="center" width="90"/>
          <el-table-column prop="all_son_num" label="代理总人数" align="center" width="120"/>
          <el-table-column prop="first_pay_money" label="首充金额" align="center" width="120"/>
          <el-table-column prop="first_pay_time" label="首充时间" align="center" width="180"/>
          <el-table-column prop="recharge_total" label="个人总充值" align="center" width="120"/>
          <el-table-column prop="withdrawal_total" label="个人总提现" align="center" width="120"/>
          <el-table-column prop="withdrawal_today" label="个人今日提现" align="center" width="120"/>
          <el-table-column prop="agent_total_pay_money" label="代理总充值" align="center" width="120"/>
          <el-table-column prop="agent_total_cash_money" label="代理总提现" align="center" width="120"/>
          <el-table-column prop="agent_today_cash_money" label="代理今日提现" align="center" width="120"/>
          <el-table-column prop="user_balance" label="剩余卢比" align="center" width="120"/>
          <el-table-column prop="top_id" label="顶级ID" align="center" width="90"/>
          <el-table-column prop="parent_id" label="上级ID" align="center" width="90"/>
          <el-table-column prop="self_invite_code" label="邀请码" align="center" width="150" show-overflow-tooltip/>
          <el-table-column prop="created_at" label="注册时间" align="center" width="180"/>
          <el-table-column prop="reg_ip" label="注册IP" align="center" width="150"/>
          <el-table-column prop="reg_machine" label="注册设备" align="center" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-show="scope.row.reg_machine" class="item_details" @click="checkedItem = scope.row,isShowMobileDetails = true">{{ scope.row.reg_machine }}</span>
              <span v-show="!scope.row.reg_machine">--</span>
            </template>
          </el-table-column>
          <el-table-column prop="login_time" label="登录时间" align="center" width="180"/>
          <el-table-column prop="login_ip" label="登录IP" align="center" width="180"/>
          <el-table-column prop="login_machine" label="登陆设备" align="center" width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-show="scope.row.login_machine" class="item_details" @click="checkedItem = scope.row,isShowMobileDetails = true">{{ scope.row.login_machine }}</span>
              <span v-show="!scope.row.login_machine">--</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="is_arrived_hall" label="是否到达大厅"  width="150">
            <template slot-scope="scope">
              <el-tag :type="scope.row.is_arrived_hall==1?'success':'info'">{{ scope.row.is_arrived_hall==1?'到达':'未到达'}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="last_action" label="最后一步操作"  width="150" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ pointLabel(scope.row.last_action) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="ban_reason" label="封禁|解封理由" align="center" width="240" show-overflow-tooltip/>
        </template>
        <template v-slot:footer>
          <pagination :total="currentTotal" :page.sync="listQuery.page" :limit.sync="listQuery.size" @pagination="getDataList" />
        </template>
      </search-table>
      <!-- 账户管理 -->
      <div>
        <el-dialog title="账户管理" :visible.sync="isShowDetails" width="50%" :before-close="onHideDetails" :close-on-click-modal="false">
          <span class="box-title flexStart">
            封禁理由：
            <el-input class="width90" type="textarea" :rows="3" v-model="bannedReason" placeholder="请输入更改理由"></el-input>
          </span>
          <span class="box-title flex marginT20" v-if="checkedItem && checkedItem.ban_type==1?true:false">
            封禁类型：
            <el-select class="width360" v-model="isBanned" placeholder="请选择封禁类型" filterable multiple>
              <el-option v-show="item.value!=1" :label="item.label" :value="item.value" v-for="(item, index) in bannedData" :key="index"></el-option>
            </el-select>
          </span>
          <span slot="footer" class="dialog-footer">
            <el-button @click="isShowDetails = false">取 消</el-button>
            <el-button type="primary" @click="bannedItem">确 定</el-button>
          </span>
        </el-dialog>
        <!-- 账户类型 -->
        <el-dialog title="账户类型" :visible.sync="isShowTypeDetails" width="50%" :before-close="onHideDetails">
          <div class="marginB10 flex" v-show="checkedItem && !checkedItem.top_id" style="font-size:16px;font-wight:600">
            <span class="marginR10 marginT10" >是否设置该用户为KOL:</span>
            <el-radio-group v-model="kolType">
              <el-radio-button :label="1">是</el-radio-button>
              <el-radio-button :label="0">否</el-radio-button>
            </el-radio-group>
          </div>
          <el-checkbox-group v-model="accountTypeData" @change="chooseType" :disabled="checkedItem && checkedItem.account_type==[16] && accountTypeShow?true:false" >
            <el-checkbox class="marginR10 marginT10" :label="item.value" border v-for="(item,index) in ACCOUNT_TYPE" :key="index" size="medium">{{item.label}}</el-checkbox>
          </el-checkbox-group>
          <el-input class="marginT20" type="textarea" :rows="3" v-model="bannedReason" placeholder="请输入更改理由"></el-input>
          <span slot="footer" class="dialog-footer">
            <el-button size="medium" @click="isShowTypeDetails = false">取 消</el-button>
            <el-button size="medium" type="primary" @click="setAccount">确 定</el-button>
          </span>
        </el-dialog>
      </div>
      <!-- 道具扣除 -->
      <div>
        <el-dialog title="道具扣除" :visible.sync="isShowPropDetails" width="50%" :before-close="onHideDetails" :close-on-click-modal="false">
          <el-select class="width100" v-model="deduct" placeholder="请选择扣除道具" filterable multiple @change="choosePropItem">
            <el-option :label="item.label" :value="item.value" v-for="(item,index) in propData" :key="index"></el-option>
          </el-select>
          <div v-show="deductData.length" class="flexWrap marginT20">
            <div class="prooItem" v-for="(item, index) in deductData" :key="index">
              <p style="margin: 0 0 5px 0;">{{ item.label }}：</p>
              <el-input-number :min="0" :max="999999999999" :precision="0" v-model="item.item_value" controls-position="right" clearable placeholder="请输入道具数量" style="width:200px"/>
            </div>
          </div>
          <el-input class="marginT20" type="textarea" :rows="3" v-model="bannedReason" placeholder="请输入扣除理由"></el-input>
          <span slot="footer" class="dialog-footer">
            <el-button size="medium" @click="isShowPropDetails = false">取 消</el-button>
            <el-button size="medium" type="primary" @click="isShowDeductDetails = true">确 定</el-button>
          </span>
        </el-dialog>
        <el-dialog title="扣除道具" :visible.sync="isShowDeductDetails" width="50%" top="200px" :before-close="onHideDetails" modal-append-to-body :close-on-click-modal="false">
          <div class="propDeduct" style="margin-top:-20px">
            <p v-if="checkedItem">确认扣除玩家：【 <span class="colorRed">{{checkedItem.nick_name}}</span> 】( {{checkedItem.id}} )的道具</p>
            <div class="flexWrap marginT20">
              <div class="marginR10" v-for="(item, index) in deductData" :key="index">
                <span>{{ item.label }}：【<span class="colorRed">{{ item.item_value }}</span>】</span>
              </div>
            </div>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button size="medium" @click="isShowDeductDetails = false">取 消</el-button>
            <el-button size="medium" type="primary" @click="resourceDeduct">确 定</el-button>
          </span>
        </el-dialog>
      </div>
      <!-- 修改密码 -->
      <div>
        <el-dialog title="修改密码" :visible.sync="isShowPasswordDetails" width="50%" top="200px"  :before-close="onHideDetails" :close-on-click-modal="false">
          <el-input type="text" :rows="3" v-model="userPassword" placeholder="请输入新密码"></el-input>
          <span slot="footer" class="dialog-footer">
            <el-button size="medium" @click="isShowPasswordDetails = false">取 消</el-button>
            <el-button size="medium" type="primary" @click="password">确 定</el-button>
          </span>
        </el-dialog>
      </div>
      <!-- 添加账号 -->
      <div>
        <el-dialog title="添加账号" :visible.sync="isShowAccountDetails" width="50%" :before-close="onHideDetails" :close-on-click-modal="false">
          <!-- <el-radio-group v-model="accountFrom.type">
            <el-radio class="marginR10 marginT10" v-for="(item,index) in ACCOUNT_TYPE" :key="index" border :label="item.value">{{item.label}}</el-radio>
          </el-radio-group> -->
          <el-checkbox-group v-model="accountFrom.type" @change="chooseType">
            <el-checkbox class="marginR10 marginT10" :label="item.value" border v-for="(item,index) in ACCOUNT_TYPE" :key="index" size="medium">{{item.label}}</el-checkbox>
          </el-checkbox-group>
          <div class="marginT20">
            <span class="box-title"><span class="mustPass marginR5">*</span>渠道：</span>
            <el-select v-model="accountFrom.agent_id" placeholder="请选择渠道" filterable >
              <el-option :label="'【'+item.value+'】'+item.label" :value="item.value" v-for="(item, index) in channelData" :key="index"></el-option>
            </el-select>
          </div>
          <div class="marginT10 flex">
            <span class="box-title"><span class="mustPass marginR5">*</span>账号：</span>
            <el-input class="width240" oninput="value=value.replace(/[^0-9.]/g,'')" @blur="accountFrom.account = $event.target.value" maxlength="10" v-model.number="accountFrom.account" placeholder="请输入手机号"/>
            <span class="colorRed marginL10">(请输入手机号)</span>
          </div>
          <div class="marginT10 flex">
            <span class="box-title">邀请人ID：</span>
            <el-input class="width40" type="number" v-model="accountFrom.parent_id" placeholder="请输入邀请人ID"/>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button size="medium" @click="isShowAccountDetails = false">取 消</el-button>
            <el-button size="medium" type="primary" @click="addUserAccount">确 定</el-button>
          </span>
        </el-dialog>
      </div>
      <page-details :show="isShowUserDetails" :data="checkedItem" @onHideDetails="onHideDetails" />
      <mobile-details :show="isShowMobileDetails" :data="checkedItem" @onHideDetails="onHideDetails" />
    </div>
  </div>
</template>

<script>
import {
  throttle
} from '@/utils/index'
import {
  getUser,
  userBanned,
  userWhite,
  resourceDeduction,
  userEditPassword,
  addAccount,
  userCode
} from '@/api/player'
import {
  ACCOUNT_TYPE,
  POINT_TYPE
} from '@/utils/enum'
import PageDetails from './page-details'
import MobileDetails from './mobile-details'
import SearchTable from '@/components/SearchTable'
export default {
  name: 'account',
  components: {
    PageDetails,
    MobileDetails,
    SearchTable
  },
  data () {
    return {
      ACCOUNT_TYPE,
      POINT_TYPE,
      propData:this.$store.state.commonState.propDataArray,
      channelData: this.$store.state.commonState.channelDataArray,
      listQuery: {
        page: 1,
        size: 50,
        search_type:1,
        search_value:'',
        agent_id:'',
        reg_ip:'',
        pay_money:'',
        cash_money:'',
        ban_type: 0, // 是否封禁
        is_line:-1, // 是否在线
        registerTime:[],
        loginTime:[],
        login_time_start: 0, //登录开始时间
        login_time_end: 0, //登录结束时间
        start_time: 0, //注册开始时间
        end_time: 0, //注册结束时间
      },
      checkedItem: null,
      isShowDetails: false,
      isShowMobileDetails: false,
      isShowUserDetails: false,
      isShowTypeDetails: false,
      isShowPropDetails: false,
      isShowDeductDetails: false,
      isShowPasswordDetails: false,
      isShowAccountDetails: false,
      accountFrom:{
        type:[],
        account:'',
        agent_id:'',
        parent_id:'',
      },
      accountTypeData: [],
      accountTypeShow: false,
      kolType: 0,
      bannedReason:'',
      userPassword:'',
      deduct:[],
      deductData:[],
      listLoading: false,
      dataList: [],
      searchData:[
        {label:'用户ID',value:1},
        {label:'昵称',value:2},
        {label:'手机号',value:3},
        {label:'邮箱',value:4},
        {label:'上级ID',value:5},
      ],
      currentTotal: 0,
      isBanned:[],
      bannedData:[
        {label:'正常用户',value:1,type:'success'},
        {label:'禁止登录',value:2,type:'info'},
        {label:'禁止提现',value:4,type:'danger'},
        {label:'禁止彩金',value:8,type:'warning'},
      ],
      bannedTypeData:[
        {label:'正常用户',value:1,type:'success'},
        {label:'禁止登录-提现',value:5,type:'info'},
        {label:'禁止登录-彩金',value:6,type:'info'},
        {label:'禁止提现-彩金',value:7,type:'danger'},
        {label:'禁止登录-提现-彩金',value:9,type:'danger'},
      ],
    }
  },
  activated(){
    this.channelData=this.$store.state.commonState.channelDataArray
    this.propData=this.$store.state.commonState.propDataArray
  },
  methods: {
    // 获取玩家列表
    async getDataList (query) {
      let that = this,params=JSON.parse(JSON.stringify(that.listQuery));
      if(query && !query.page){
        params.page=1
        params.size=50
      }
      that.dataList = []
      that.checkedItem = null
      if (params.registerTime && params.registerTime[0] && params.registerTime[1]) {
        params.start_time = that.$public.standardDate(params.registerTime[0])
        params.end_time = that.$public.standardDate(params.registerTime[1])
      } else {
        params.start_time=''
        params.end_time=''
      }
      if (params.loginTime && params.loginTime[0] && params.loginTime[1]) {
        params.login_time_start = that.$public.standardDate(params.loginTime[0])
        params.login_time_end = that.$public.standardDate(params.loginTime[1])
      } else {
        params.login_time_start=''
        params.login_time_end=''
      }
      if(params.pay_money){
        params.pay_money=that.$public.mathNumberMultiply(params.pay_money,10000)
      }
      if(params.cash_money){
        params.cash_money=that.$public.mathNumberMultiply(params.cash_money,10000)
      }
      const response = await getUser(params)
      if (response.code == 1) {
        if(response.data){
          response.data.list.forEach(item => {
            item.isChecked = false
            item.first_pay_money=that.$public.mathNumberDivideWan(item.first_pay_money)
            item.recharge_total=that.$public.mathNumberDivideWan(item.recharge_total)
            item.withdrawal_total=that.$public.mathNumberDivideWan(item.withdrawal_total)
            item.withdrawal_today=that.$public.mathNumberDivideWan(item.withdrawal_today)
            item.agent_total_pay_money=that.$public.mathNumberDivideWan(item.agent_total_pay_money)
            item.agent_total_cash_money=that.$public.mathNumberDivideWan(item.agent_total_cash_money)
            item.agent_today_cash_money=that.$public.mathNumberDivideWan(item.agent_today_cash_money)
            item.user_balance=that.$public.mathNumberDivideWan(item.user_balance)
          })
          that.dataList = response.data.list
          that.currentTotal = response.data.total
        }
      }else{
        that.$message.error(error.msg)
      }
      that.listLoading = false
    },
    // 获取账号列表
    getAccountIpList (row) {
      let that = this,params=that.listQuery;
      that.listQuery.registerTime=[]
      that.listQuery.loginTime=[]
      that.dataList = []
      params.reg_ip=row.reg_ip
      params.start_time=''
      params.end_time=''
      params.login_time_start=''
      params.login_time_end=''
      getUser(params).then(res => {
        if (res.code == 1) {
          res.data.list.forEach(item => {
            item.isChecked = false
            item.first_pay_money=that.$public.mathNumberDivideWan(item.first_pay_money)
            item.recharge_total=that.$public.mathNumberDivideWan(item.recharge_total)
            item.withdrawal_total=that.$public.mathNumberDivideWan(item.withdrawal_total)
            item.withdrawal_today=that.$public.mathNumberDivideWan(item.withdrawal_today)
            item.agent_total_pay_money=that.$public.mathNumberDivideWan(item.agent_total_pay_money)
            item.agent_total_cash_money=that.$public.mathNumberDivideWan(item.agent_total_cash_money)
            item.agent_today_cash_money=that.$public.mathNumberDivideWan(item.agent_today_cash_money)
            item.user_balance=that.$public.mathNumberDivideWan(item.user_balance)
          })
          that.dataList = res.data.list
          that.currentTotal = res.data.total
        }
        that.listLoading = false
      }).catch((error) => {
        that.listLoading = false
        that.$message.error(error.msg)
      })
    },
    // 封禁解封
    bannedItem(){
      let that = this,row=that.checkedItem;
      if(!that.bannedReason){
        return that.$message.error('请输入更改理由！')
      }
      let query = {
        ban_type: that.isBanned.reduce((total, current) =>total + current),
        list_type: 1,
        reason: that.bannedReason,
        ban_content:row.id.toString()
      }
      userBanned(query).then(res => {
        if (res.code == 1) {
          that.$message({
            type: 'success',
            message: res.msg
          })
          that.onHideDetails(true)
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 账号类型选择
    chooseType(val){
      // isShowTypeDetails:设置账户类型  isShowAccountDetails:添加账户 
      let data=[];
      if(!val.find((item) => item == 2)){
        data=val
      }else if(val.find((item) => item == 2) && val.length!=1 &&val[0]==2){
        val.forEach((item,index)=>{
          if(item==2){
            val.splice(index,1)
          }
        })
        data=val
      }else{
        data=[2]
      }
      if(this.isShowAccountDetails){
        this.accountFrom.type=data
      }else{
        this.accountTypeData=data
      }
    },
    // 设置账号类型
    setAccount(){
      let that = this,row=that.checkedItem;
      if(!that.bannedReason){
        return that.$message.error('请输入更改理由！')
      }
      userWhite({
        account_type: that.accountTypeData.reduce((total, current) =>total + current),
        is_kol: that.kolType,
        user_id: row.id,
        operated_id:  row.operated_id, 
        reason: that.bannedReason
      }).then(res => {
        if (res.code == 1) {
          that.$message({
            type: 'success',
            message: res.msg
          })
          that.onHideDetails(true)
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 新增账号
    addAccountShow(){
      this.isShowAccountDetails = true
      this.accountFrom={
        type:[],
        account:'',
        agent_id:'',
        parent_id:'',
      }
    },
    addUserAccount(){
      let that = this, params = JSON.parse(JSON.stringify(that.accountFrom));
      if(!params.account){
        return that.$message.error('请输入手机号')
      }else{
        if(params.account.substring(0,1)==0){
          return that.$message.error('请输入正确的手机号,首位数字不能为0')
        }else if(params.account && params.account.length>11){
          return that.$message.error('请输入正确的手机号')
        }
      }
      if(!params.agent_id){
        return that.$message.error('请选择渠道')
      }
      addAccount({
        account_type: params.type.reduce((total, current) =>total + current),
        account: Number(params.account), 
        agent_id: params.agent_id,
        parent_id: Number(params.parent_id),
      }).then(res => {
        if (res.code == 1) {
          that.$message({
            type: 'success',
            message: res.msg
          })
          setTimeout(function (){
            that.onHideDetails(true)
          },1000);
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 选择道具
    choosePropItem (val) {
      let that = this;
      that.deductData = []
      that.propData.map(item => {
        val.map(first => {
          if (item.value == first) {
            that.deductData.push({label:item.label,item_type:item.value,item_value:0})
          }
        })
      })
    },
    // 扣除道具
    resourceDeduct(){
      let that = this,row=that.checkedItem,propData=JSON.parse(JSON.stringify(that.deductData));
      if(!that.bannedReason){
        return that.$message.error('请输入扣除理由！')
      }
      propData.map(item=>{
        item.item_value=that.$public.mathNumberMultiply(item.item_value,10000)
      })
      resourceDeduction({
        user_id: row.id,
        item_info_data: propData,
        reason: that.bannedReason
      }).then(res => {
        if (res.code == 1) {
          that.$message({
            type: 'success',
            message: res.msg
          })
          that.onHideDetails(true)
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 获取验证码
    getCode(row){
      let that = this;
      that.handleCurrentChange(row)
      userCode({
        mobile: row.mobile,
        mobile_prefix: row.mobile_prefix,
        operated_id: row.operated_id,
      }).then(res => {
        if (res.code == 1) {
          that.$alert(`登录验证码:<span class='fontSize18 colorGre marginL10'>${res.data.result}</span>`, '登录验证码', {
            dangerouslyUseHTMLString: true,
            confirmButtonText: '确定',
            callback: action => {}
          })
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 修改密码
    password(){
      let that = this,row=that.checkedItem;
      if(!that.userPassword){
        return that.$message.error('请输入更改新密码')
      }
      userEditPassword({
        user_id: row.id,
        pwd: that.userPassword
      }).then(res => {
        if (res.code == 1) {
          that.$message({
            type: 'success',
            message: res.msg
          })
          that.onHideDetails(true)
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 账号类型展示
    accountType(cellValue){
      return (this.ACCOUNT_TYPE.find((item) => item.value === cellValue)?.label || "测试账号");
    },
    // 账号类型展示
    accountTag(cellValue){
      return (this.ACCOUNT_TYPE.find((item) => item.value === cellValue)?.type || "-");
    },
    // 账号封禁展示
    bannedType(cellValue){
      let arr = []
      this.bannedData.forEach(item => {
        if ((cellValue & item.value) == item.value) {
          arr.push(item.label)
        }
      })
      return arr.toString()
    },
    // 账号类型展示
    bannedTag(cellValue){
      return (this.bannedTypeData.find((item) => item.value === cellValue)?.type || "-");
    },
    // 埋点类型展示
    pointLabel(cellValue){
      if(cellValue){
        return (this.POINT_TYPE.find((item) => item.value === cellValue)?.label || "-");
      }
    },
    // 分享链接
    shareUrl(row) {
      window.open(row.share_url)
    },
    // 登录
    loginManage (row) {
      let that = this;
      getToken({
        id: row.id
      }).then(function (res) {
        if (res.code) {
          if (res.data) {
            window.open(that.manageUrl + '#/login?redirect=%2instrument&TOKENOPERTOR=' + res.data)
          }
        }
      }).catch((error) => {
        that.$message.error(error.msg)
      })
    },
    // 选择表格数据
    handleCurrentChange (val) {
      this.accountTypeData=[]
      // 用户账户类型
      if(val.account_type==2){
        this.accountTypeData=[2]
        this.accountTypeShow=false
      }else if(val.account_type==4){
        this.accountTypeData=[4]
        this.accountTypeShow=false
      }else if(val.account_type==8){
        this.accountTypeData=[8]
        this.accountTypeShow=false
      }else if(val.account_type==12){
        this.accountTypeData=[4,8]
        this.accountTypeShow=false
      }else if(val.account_type==16){
        this.accountTypeData=[16]
        this.accountTypeShow=true
      }else if(val.account_type==20){
        this.accountTypeData=[4,16]
        this.accountTypeShow=true
      }else if(val.account_type==24){
        this.accountTypeData=[8,16]
        this.accountTypeShow=true
      }
      this.checkedItem = val
      this.kolType=val.is_kol
      this.dataList.map(item => {
        if (item.id === val.id) {
          item.isChecked = true
        } else {
          item.isChecked = false
        }
      })
    },
    onHideDetails (status) {
      this.isShowDetails = false
      this.isShowMobileDetails = false
      this.isShowUserDetails = false
      this.isShowTypeDetails = false
      this.isShowPropDetails = false
      this.isShowDeductDetails = false
      this.isShowPasswordDetails = false
      this.isShowAccountDetails = false
      this.kolType = 0
      this.deduct = []
      this.deductData = []
      this.bannedReason=''
      this.isBanned=[]
      if(status){
        this.getDataList()
      }
    },
    // 刷新
    refresh: throttle(function () {
      this.listQuery = {
        page: 1,
        size: 50,
        search_type:1,
        search_value:'',
        reg_ip:'',
        agent_id:'',
        pay_money:'',
        cash_money:'',
        ban_type: 0, // 是否封禁
        is_line:-1, // 是否在线
        registerTime:[],
        loginTime:[],
        login_time_start: 0, //登录开始时间
        login_time_end: 0, //登录结束时间
        start_time: 0, //注册开始时间
        end_time: 0, //注册结束时间
      }
      this.getDataList(true)
    }, 2000),
  }
}
</script>

<style lang="scss" scoped>
.prooItem {
  margin: 10px;
  font-size: 18px;
  font-weight: 550;
  p {
    height: 21px;
  }
}
.propDeduct{
  font-size: 18px;
  font-weight: 600;
  .colorRed{
    font-size: 21px;
  }
}
</style>
